/*********************************************************
 *
 *  Ports all the way down - patwd
 *  ------------------------------
 *
 *  debug.h
 *
 *  Copyright (C) 2012 by Sebastian Roschke (bykhee@gmail.com)
 *
 *  Logging and debug function definitions.
 *
 *  Distributed under the terms and conditions of GNU LGPL.
 *
 *********************************************************/

#define LBUFSIZE 256
#define MAX_ALLOC           0x40000000
#define NUM_PORTS 65535

#include "types.h"

int log_level;

void log_debug(u8* msg);

void log_error(u8* msg);

void logg(u8 *msg);

void print_dump(void* data, int size);

/**********************************************************
 *
 *  borrowed from Michal Zalewski's p0f3
 *  Thx Michal!
 *
 **********************************************************/

#ifndef _HAVE_DEBUG_H
#define _HAVE_DEBUG_H

#ifdef DEBUG_BUILD
#  define DEBUG(x...) fprintf(stderr, x)
#else
#  define DEBUG(x...) do {} while (0)
#endif /* ^DEBUG_BUILD */

#define ERRORF(x...)  fprintf(stderr, x)
#define SAYF(x...)    printf(x)

#define WARN(x...) do { \
    ERRORF("[!] WARNING: " x); \
    ERRORF("\n"); \
  } while (0)

#define FATAL(x...) do { \
    ERRORF("[-] PROGRAM ABORT : " x); \
    ERRORF("\n         Location : %s(), %s:%u\n\n", \
           __FUNCTION__, __FILE__, __LINE__); \
    exit(1); \
  } while (0)

#define ABORT(x...) do { \
    ERRORF("[-] PROGRAM ABORT : " x); \
    ERRORF("\n         Location : %s(), %s:%u\n\n", \
           __FUNCTION__, __FILE__, __LINE__); \
    abort(); \
  } while (0)

#define PFATAL(x...) do { \
    ERRORF("[-] SYSTEM ERROR : " x); \
    ERRORF("\n        Location : %s(), %s:%u\n", \
           __FUNCTION__, __FILE__, __LINE__); \
    perror("      OS message "); \
    ERRORF("\n"); \
    exit(1); \
  } while (0)

#endif /* ! _HAVE_DEBUG_H */

